package cn.qhuan.modules.service.impl;

import cn.qhuan.modules.constos.StatusConstos;
import cn.qhuan.modules.dtos.ResumeAuthDto;
import cn.qhuan.modules.entity.Resume;
import cn.qhuan.modules.mapper.ResumeMapper;
import cn.qhuan.modules.service.IResumeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 简历表
 * @Author: 司翔宇
 * @Date:   2020-12-30
 * @Version: V1.0
 */
@Service
public class ResumeServiceImpl extends ServiceImpl<ResumeMapper, Resume> implements IResumeService {
    @Autowired
    private ResumeMapper resumeMapper;
    @Override
    public Result<?> queryResumeByArtistId(String id) {
        //1.检查参数
        if (id == null ){
            return Result.error("缺少参数");
        }
        List<Resume> list = resumeMapper.queryResumeByArtistId(id);
        List<Resume> resumeList =new ArrayList<>();
        for (Resume resume : list) {
            if (resume.getState().equals(StatusConstos.STATUS_PASS)){
                resumeList.add(resume);
            }
        }
        return Result.OK(resumeList);
    }

    @Override
    public Result<?> updateStatus(ResumeAuthDto dto, Integer type) {
        //1.检查参数
        if (dto ==null || dto.getId() == null ){
            return Result.error("缺少参数");
        }
        //2.查询作品信息
        Resume resume = resumeMapper.selectById(dto.getId());

        if (resume == null){
            return Result.error("专业简历不存在");
        }
        //3.审核失败
        if (type.equals(StatusConstos.STATUS_FAIL)){
            updateArtist(resume,StatusConstos.STATUS_FAIL);
        }else if (type.equals(StatusConstos.STATUS_PASS)){
            updateArtist(resume,StatusConstos.STATUS_PASS);
        }
        return Result.OK("修改成功");
    }
    /**
     * 修改作品信息
     * @param resume
     * @param status
     *
     */
    private void updateArtist (Resume resume,Integer status){
        resume.setState(status);
        resumeMapper.updateById(resume);
    }
}
